<?php
class Zendvn_View_Helper_CheckYahoo extends Zend_View_Helper_Abstract{
    protected $url;

    public function checkYahoo($account) {
        $this->url = 'http://opi.yahoo.com/online?u=' . $account;
        if($this->checkStatus()){
            echo "<img src='".$this->view->baseUrl() . '/online.jpg' . "' />";
        }else{
            echo "<img src='".$this->view->baseUrl() . '/offline.jpg' . "' />";
        }
    }

    protected function checkStatus() {
        $ch = curl_init($this->url);
        curl_setopt($ch, CURLOPT_URL, $this->url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        ob_start();
        curl_exec($ch);
        $content = ob_get_contents();
        curl_close($ch);
        ob_get_clean();
        if (trim(strtolower(strip_tags($content))) != 'user not specified.') {
            return (strlen($content) == 140) ? TRUE : FALSE;
        }
        return FALSE;
    }
}